var HtmlWebPackPlugin =require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CompressionPlugin    = require('compression-webpack-plugin');
const path                 = require('path');
      module.exports       = {
    module:{
        rules:[
            {
                test   : /\.(js|jsx)$/,
                exclude: /node_modules/,
                use    : {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.html$/,
                use : [{
                    loader : "html-loader",
                    options: {
                        minimize: true
                    }
                }]
            },
            
            {
                test: /\.(png|jpg|gif)$/,
                use : [{ loader: 'url-loader' }]
            },
            {
                test: /\.css$/,
                use : [
                  MiniCssExtractPlugin.loader,
                  'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
                ]
            },
            {
                test: /\.scss$/,
                use : [
                    MiniCssExtractPlugin.loader,
                    'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
                    'sass-loader'
                ]
            },
            {
                test   : /\.(png|jpg|gif|svg)$/,
                loader : 'file-loader',
                options: {
                  name: '[name].[ext]?[hash]'
                }
            }

        ]
    },
    // devServer:{
    //     contentBase     : './src',
    //     watchContentBase: true
    // },
    resolve: {
        alias: {
          '@': path.resolve('./src'),
          '~': path.resolve('./static')
        },
        extensions: ['*', '.js']
      },
    plugins:[
        new HtmlWebPackPlugin({
            template: "./src/index.html",
            filename: "./index.html"
          }),
          new MiniCssExtractPlugin({
              filename     : "[name].css",
              chunkFilename: "[id].css"
          }),
          new CompressionPlugin({
            test   : /\.js(\?.*)?$/i,
            exclude: /\/excludes/
          })
    ]
}